package cn.edu.Day06.service.Impl;

import cn.edu.Day06.Entity.Bullet;
import cn.edu.Day06.Entity.Plane;
import cn.edu.Day06.service.BulletService;

import java.awt.*;
import java.util.List;

public class BulletServiceImpl implements BulletService{
    public void createBullet(List<Bullet> list, Plane plane) {
        Bullet bullet = new Bullet();
        bullet.setX(plane.getX()+plane.getWidth()/2-bullet.getWidth()/2);
        bullet.setY(plane.getY()+plane.getHeight()/3-bullet.getHeight()/2);
        list.add(bullet);
    }
    public void drawBullets(Graphics g, List<Bullet> bullets) {
        if (bullets.size()>0){
            for (int i = 0; i < bullets.size(); i++) {
                Bullet b = bullets.get(i);
                g.drawImage(Bullet.IMG1,b.getX(),b.getY(),b.getWidth(),b.getHeight(),null);
            }
        }

    }
    public void up(List<Bullet> bullets) {
        if (bullets.size()>0){
            for (int i = 0; i < bullets.size(); i++) {
                Bullet b = bullets.get(i);
                b.setY(b.getY()-b.getSpeed());//子弹的速度 .
                if (b.getY()<=0-b.getHeight()){
                    bullets.remove(i);
                }
            }
        }

    }
}
